package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章的数据模型
 */
@Getter
@Setter
public class StrategyDetail extends BaseDomain{

    public static final Integer STATE_RELEASE = 0; //发布
    public static final Integer STATE_TEMP = 1; //草稿

    private String title;//标题

    private Date createTime;//创建时间

    private Date releaseTime;//发布时间

    private Integer sequence;//序号

    private Strategycatalog catalog;//所属分类的信息

    private String coverUrl;//封面

    private Integer state = STATE_TEMP;//状态

    private StrategyContent strategyContent ;//文章的内容

    public String getStateName(){
        String msg = "草稿" ;
        if(state==STATE_RELEASE){
            msg = "发布" ;
        }
        return msg ;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        map.put("state",state);
        if(catalog!=null){
            map.put("strategyId",catalog.getStrategyId());
            //将自己的id页存储进去
            map.put("catalogId",catalog.getId());
        }

        return JSONUtil.toJSONString(map);
    }

}